using RAG.Domain.Entities.App;

namespace RAG.Domain.Repositories;

/// <summary>
/// 知识库仓储接口
/// </summary>
public interface IKnowledgeBaseRepository : IRepository<KnowledgeBase>
{
    /// <summary>
    /// 向量相似性搜索
    /// </summary>
    /// <param name="queryVector">查询向量</param>
    /// <param name="limit">返回结果数量</param>
    /// <param name="threshold">相似度阈值</param>
    /// <returns>相似的知识库条目</returns>
    Task<List<KnowledgeBase>> SearchSimilarAsync(float[] queryVector, int limit = 10, double threshold = 0.7);

    /// <summary>
    /// 根据文档类型搜索
    /// </summary>
    /// <param name="documentType">文档类型</param>
    /// <returns>知识库条目列表</returns>
    Task<List<KnowledgeBase>> GetByDocumentTypeAsync(string documentType);

    /// <summary>
    /// 根据嵌入类型搜索
    /// </summary>
    /// <param name="embeddingType">嵌入类型</param>
    /// <returns>知识库条目列表</returns>
    Task<List<KnowledgeBase>> GetByEmbeddingTypeAsync(string embeddingType);

    /// <summary>
    /// 根据标题模糊搜索
    /// </summary>
    /// <param name="title">标题关键词</param>
    /// <returns>知识库条目列表</returns>
    Task<List<KnowledgeBase>> SearchByTitleAsync(string title);

    /// <summary>
    /// 根据内容模糊搜索
    /// </summary>
    /// <param name="content">内容关键词</param>
    /// <returns>知识库条目列表</returns>
    Task<List<KnowledgeBase>> SearchByContentAsync(string content);

    /// <summary>
    /// 根据块ID获取知识库条目
    /// </summary>
    /// <param name="chunkId">块ID</param>
    /// <returns>知识库条目列表</returns>
    Task<List<KnowledgeBase>> GetByChunkIdAsync(Guid chunkId);

    /// <summary>
    /// 删除指定块的所有知识库条目
    /// </summary>
    /// <param name="chunkId">块ID</param>
    /// <returns>删除的条目数量</returns>
    Task<int> DeleteByChunkIdAsync(Guid chunkId);

    /// <summary>
    /// 获取知识库总条数
    /// </summary>
    Task<int> CountAllAsync();

    /// <summary>
    /// 按嵌入类型分组统计数量
    /// </summary>
    Task<Dictionary<string, int>> CountByEmbeddingTypeAsync();

    /// <summary>
    /// 分页查询（按关键字/文档/类型）
    /// </summary>
    Task<(List<KnowledgeBase> Items, int Total)> QueryAsync(string? keyword, Guid? documentId, string? documentType, int page, int pageSize);
}
